package weibo.crawler.UO;
// default package

import data.process.UO.BaseHibernateDAO;
import java.util.Date;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.Transaction;
import org.hibernate.criterion.Example;


/**
 	* A data access object (DAO) providing persistence and search support for RawUserUO entities.
 			* Transaction control of the save(), update() and delete() operations 
		can directly support Spring container-managed transactions or they can be augmented	to handle user-managed Spring transactions. 
		Each of these methods provides additional information for how to configure it for the desired type of transaction control. 	
	 * @see .RawUserUO
  * @author MyEclipse Persistence Tools 
 */

public class RawUserUODAO extends BaseHibernateDAO  {
    private static final Log log = LogFactory.getLog(RawUserUODAO.class);
	//property constants
	public static final String UID = "uid";
	public static final String SCREEN_NAME = "screenName";
	public static final String PROVINCE = "province";
	public static final String CITY = "city";
	public static final String LOCATION = "location";
	public static final String DESCRIPTION = "description";
	public static final String URL = "url";
	public static final String GENDER = "gender";
	public static final String FOLLOWERS_COUNT = "followersCount";
	public static final String FRIENDS_COUNT = "friendsCount";
	public static final String STATUSES_COUNT = "statusesCount";
	public static final String VERIFIED = "verified";
	public static final String VERIFIED_TYPE = "verifiedType";
	public static final String BI_FOLLOWERS_COUNT = "biFollowersCount";
	public static final String REMARK = "remark";
	public static final String VERIFIED_REASON = "verifiedReason";



    
    public void save(RawUserUO transientInstance) {
        log.debug("saving RawUserUO instance");
        try {
        	getSession().beginTransaction();
            getSession().save(transientInstance);
            getSession().getTransaction().commit();
            log.debug("save successful");
        } catch (RuntimeException re) {
            log.error("save failed", re);
            throw re;
        }
    }
    
	public void delete(RawUserUO persistentInstance) {
        log.debug("deleting RawUserUO instance");
        try {
            getSession().delete(persistentInstance);
            log.debug("delete successful");
        } catch (RuntimeException re) {
            log.error("delete failed", re);
            throw re;
        }
    }
    
    public RawUserUO findById( java.lang.Integer id) {
        log.debug("getting RawUserUO instance with id: " + id);
        try {
            RawUserUO instance = (RawUserUO) getSession()
                    .get("RawUserUO", id);
            return instance;
        } catch (RuntimeException re) {
            log.error("get failed", re);
            throw re;
        }
    }
    
    
    public List findByExample(RawUserUO instance) {
        log.debug("finding RawUserUO instance by example");
        try {
            List results = getSession()
                    .createCriteria("RawUserUO")
                    .add(Example.create(instance))
            .list();
            log.debug("find by example successful, result size: " + results.size());
            return results;
        } catch (RuntimeException re) {
            log.error("find by example failed", re);
            throw re;
        }
    }    
    
    public List findByProperty(String propertyName, Object value) {
      log.debug("finding RawUserUO instance with property: " + propertyName
            + ", value: " + value);
      try {
         String queryString = "from RawUserUO as model where model." 
         						+ propertyName + "= ?";
         Query queryObject = getSession().createQuery(queryString);
		 queryObject.setParameter(0, value);
		 return queryObject.list();
      } catch (RuntimeException re) {
         log.error("find by property name failed", re);
         throw re;
      }
	}

	public List findByUid(Object uid
	) {
		return findByProperty(UID, uid
		);
	}
	
	public List findByScreenName(Object screenName
	) {
		return findByProperty(SCREEN_NAME, screenName
		);
	}
	
	public List findByProvince(Object province
	) {
		return findByProperty(PROVINCE, province
		);
	}
	
	public List findByCity(Object city
	) {
		return findByProperty(CITY, city
		);
	}
	
	public List findByLocation(Object location
	) {
		return findByProperty(LOCATION, location
		);
	}
	
	public List findByDescription(Object description
	) {
		return findByProperty(DESCRIPTION, description
		);
	}
	
	public List findByUrl(Object url
	) {
		return findByProperty(URL, url
		);
	}
	
	public List findByGender(Object gender
	) {
		return findByProperty(GENDER, gender
		);
	}
	
	public List findByFollowersCount(Object followersCount
	) {
		return findByProperty(FOLLOWERS_COUNT, followersCount
		);
	}
	
	public List findByFriendsCount(Object friendsCount
	) {
		return findByProperty(FRIENDS_COUNT, friendsCount
		);
	}
	
	public List findByStatusesCount(Object statusesCount
	) {
		return findByProperty(STATUSES_COUNT, statusesCount
		);
	}
	
	public List findByVerified(Object verified
	) {
		return findByProperty(VERIFIED, verified
		);
	}
	
	public List findByVerifiedType(Object verifiedType
	) {
		return findByProperty(VERIFIED_TYPE, verifiedType
		);
	}
	
	public List findByBiFollowersCount(Object biFollowersCount
	) {
		return findByProperty(BI_FOLLOWERS_COUNT, biFollowersCount
		);
	}
	
	public List findByRemark(Object remark
	) {
		return findByProperty(REMARK, remark
		);
	}
	
	public List findByVerifiedReason(Object verifiedReason
	) {
		return findByProperty(VERIFIED_REASON, verifiedReason
		);
	}
	

	public List findAll() {
		log.debug("finding all RawUserUO instances");
		try {
			String queryString = "from RawUserUO";
	         Query queryObject = getSession().createQuery(queryString);
			 return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}
	
    public RawUserUO merge(RawUserUO detachedInstance) {
        log.debug("merging RawUserUO instance");
        try {
            RawUserUO result = (RawUserUO) getSession()
                    .merge(detachedInstance);
            log.debug("merge successful");
            return result;
        } catch (RuntimeException re) {
            log.error("merge failed", re);
            throw re;
        }
    }

    public void attachDirty(RawUserUO instance) {
        log.debug("attaching dirty RawUserUO instance");
        try {
            getSession().saveOrUpdate(instance);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }
    
    public void attachClean(RawUserUO instance) {
        log.debug("attaching clean RawUserUO instance");
        try {
            getSession().lock(instance, LockMode.NONE);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }
}